package com.bw.servlet;

import com.bw.dao.PhoneDao;
import com.bw.pojo.Phone;
import lombok.SneakyThrows;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/***************************
 FileAction:

 CreateTime:2022-05-10 11:11
 Author:Aaking-aline
 ****************************/
@WebServlet("/SelectServlet")
public class SelectServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    @SneakyThrows
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String page = request.getParameter("page");

        List<Phone> list = new PhoneDao().selectPhoneByLimit(page);
        request.setAttribute("list",list);

        int pageNum = new PhoneDao().selectPageNum(); // 查询总数据行数一共有多少页

        request.setAttribute("page",page);
        request.setAttribute("pageNum",pageNum);

        request.getRequestDispatcher("message.jsp").forward(request,response);

    }
}
